﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using DiscoveryLogic.Common.Utilities;

namespace DiscoveryLogic.Analytics.DataObjects
{
    public class Subject:EntityBase
    {
        private string _Category;
        /// <summary></summary>
        public string Category
        {
            get
            {
                return this._Category;
            }
            set
            {
                this._Category = value;
            }
        }

        private string _Desc;
        /// <summary></summary>
        public string Desc
        {
            get
            {
                return this._Desc;
            }
            set
            {
                this._Desc = value;
            }
        }

        public Subject() 
            : base(Common.Utilities.EntityType.Subject,"Category","Desc")
        {
            this._Category = string.Empty;
            this._Desc = string.Empty;
        }

        #region Overrides of EntityBase

        /// <summary>
        /// 
        /// </summary>
        /// <param name="xDoc"></param>
        /// <param name="entityNode"></param>
        public override void Save(ref XmlDocument xDoc, XmlNode entityNode)
        {
            XmlDataUtil.UpdateAttribute(ref xDoc, entityNode, "Category", this.Category);
            XmlDataUtil.UpdateAttribute(ref xDoc, entityNode, "Description", this.Desc);
        }

        #endregion

        public static Subject Read(XmlNode entityNode)
        {
            Subject subj = new Subject();
            subj.Category = XmlDataUtil.GetAttributeValue(entityNode, "Category", "");
            subj.Desc = XmlDataUtil.GetAttributeValue(entityNode, "Description", "");
            return subj;
        }

        public static List<EntityBase> Read(XmlDocument xDoc)
        {
            List<EntityBase> docs = new List<EntityBase>();
            XmlNodeList subjNodes = xDoc.DocumentElement.SelectNodes("//Subj");
            if (subjNodes != null && subjNodes.Count > 0)
            {
                foreach (XmlNode subjNode in subjNodes)
                {
                    Subject subj = Subject.Read(subjNode);
                    docs.Add(subj);
                }
            }
            return docs;
        }
    }
}
